<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="renderer" content="webkit">
        <title>{$Think.config.laytp.basic.site_name} - 登录</title>
        <link rel="stylesheet" href="__STATIC__/admin/css/login_old.css">
        <style>
            body{ color:#333; font-size:13px;}
            input,select,textarea{color:#333;}
            .bg{ width:100%; height:100%; position:absolute; background:url(__STATIC__/admin/image/bg.jpg) }
            .panel{background:#fff;}
            form .form-group:last-child{padding-bottom:0;}
            .passcode{position:absolute;right:0;bottom:0;height:32px;margin:1px;border-left:solid 1px #ddd;text-align:center;line-height:32px;border-radius:0 4px 4px 0;}
            ul,li{ list-style-type:none;}

            .field-icon-right .icon{ bottom:0px; top:auto}
            .loginbox { background:url(__STATIC__/admin/image/tmbg-white.png); border:0px;}

            .en-markup-crop-options {
                top: 18px !important;
                left: 50% !important;
                margin-left: -100px !important;
                width: 200px !important;
                border: 2px rgba(255,255,255,.38) solid !important;
                border-radius: 4px !important;
            }

            .en-markup-crop-options div div:first-of-type {
                margin-left: 0px !important;
            }
        </style>
    </head>
    <body>
        <div class="bg"></div>
        <div class="container">
            <div class="line">
                <div class="xs6 xm4 xs3-move xm4-move">
                    <div style="height:150px;"></div>
                    <div class="media media-y margin-big-bottom">
                    </div>
                    <div class="layui-form">
                        <div class="panel loginbox">
                            <div class="text-center margin-big padding-big-top">
                                <h1>{$Think.config.laytp.basic.site_name}</h1>
                            </div>
                            <div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
                                <div class="form-group">
                                    <div class="field field-icon-right">
                                        <input type="text" class="input input-big" name="username" id="username" placeholder="登录账号" lay-verify="required" autofocus="autofocus">
                                        <span class="icon icon-user margin-small"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="field field-icon-right">
                                        <input type="password" class="input input-big" name="password" id="password" placeholder="登录密码" lay-verify="required">
                                        <span class="icon icon-key margin-small"></span>
                                    </div>
                                </div>
                                <input type="hidden" value="{$referer}" name="referer" id="referer" />
                                {if $Think.config.laytp.basic.login_vercode}
                                <div class="form-group">
                                    <div class="field field-icon-right">
                                        <input type="text" class="input input-big" id="code" name="code" placeholder="填写右侧的验证码" lay-verify="required">
                                        <img id="captcha_img" src="/verifyCode" alt="" width="150" height="32" class="passcode" style="height:43px;cursor:pointer;" />
                                    </div>
                                </div>
                                {else/}
                                <input type="hidden" name="code" value="1"/>
                                {/if}
                            </div>
                            <div style="padding:0px 30px 30px 30px">
                                <input type="button" id="submitBtn" class="button button-block bg-main text-big input-big" lay-submit lay-filter="user-login-submit" value="登 录">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

<script src="__STATIC__/library/layui/layui.js"></script>
<script>
    layui.config({
        version: false //一般用于更新模块缓存，默认不开启。设为true即让浏览器不缓存。也可以设为一个固定的值，如：201610
        ,debug: false //用于开启调试模式，默认false，如果设为true，则JS模块的节点会保留在页面
        ,base: '/static/library/layui/extends/' //设定扩展的Layui模块的所在目录，一般用于外部模块扩展
    }).use(['layTp'],function(){
        let $ = layui.$
            ,form = layui.form
            ,layTp = layui.layTp
        ;
        form.render();

        $("#captcha_img").click(function(){
            this.src = "/verifyCode?v=" + Math.random();
        });

        form.on('submit(user-login-submit)', function(obj){
            $.ajax({
                type: 'POST'
                ,url: '/admin/auth.login/do_login'
                ,data: obj.field
                ,dataType: 'json'
                ,success:function(res){
                    if(res.code == 1){
                        layTp.facade.setcookie('admin_token', res.data.admin_token, 3);
                        layTp.facade.success(res.msg);
                        setTimeout( function(){redirect(res.url)}, 1000 );
                    }else{
                        layTp.facade.error(res.msg);
                        $('#user-get-vercode').click();
                    }
                }
                ,error: function (xhr) {
                    if( xhr.status == '500' ){
                        layTp.facade.error('本地网络问题或者服务器错误');
                    }else if( xhr.status == '404' ){
                        layTp.facade.error('请求地址不存在');
                    }
                }
            });
        });

        function redirect(url)
        {
            url = url ? url : "/admin?ref=1";
            location.href = url;
        }

        {if $Think.config.laytp.basic.login_vercode}
        $("#code").focus(function()
        {
            $(document).on("keydown",function(event)
            {
                if( event.keyCode == 13 )
                {
                    $('#submitBtn').click();
                }
            });
            $("#code").unbind();
        });
        {else}
        $("#password").focus(function()
        {
            $(document).on("keydown",function(event)
            {
                if( event.keyCode == 13 )
                {
                    $('#submitBtn').click();
                }
            });
            $("#password").unbind();
        });
        {/if}
    });
</script>